﻿/// <reference path="zhx.js" />
//cutImg
$(function() {
    $("input[video]").each(function() {
        $(this).hide();
        var _img = "";
        if ($.trim($(this).val()) != "") {
            _img = '<object type="application/x-shockwave-flash" data="' + toolsPath() + 'flash/vcastr3.swf" style="width:240px;height:160px;">'
                + '<param name="movie" value="' + toolsPath() + 'flash/vcastr3.swf" />'
                + '<param name="allowFullScreen" value="true" />'
                + '<param name="wmode" value="transparent" />'
                + '<param name="FlashVars" value="xml=<vcastr>'
                + '<channel>'
                + '<item>'
                + '<source>' + $.trim($(this).val()) + '</source>'
                + '<duration></duration>'
                + '<title></title>'
                + '</item>'
                + '</channel>'
                + '<config>'
                + '<bufferTime>4</bufferTime>'
                + '<contralPanelAlpha>0.75</contralPanelAlpha>'
                + '<controlPanelBgColor>0xff6600</controlPanelBgColor>'
                + '<controlPanelBtnColor>0xffffff</controlPanelBtnColor>'
                + '<contralPanelBtnGlowColro>0xffff00</contralPanelBtnGlowColro>'
                + '<controlPanelMode>normal</controlPanelMode>'
                + '<defautVolume>0.7</defautVolume>'
                + '<isAutoPlay>false</isAutoPlay>'
                + '<isLoadBegin>true</isLoadBegin>'
                + '<isShowAbout>false</isShowAbout>'
                + '<scaleMode>showAll</scaleMode>'
                + '<isRepeat>false</isRepeat>'
                + '</config>'
                + '</vcastr>" />'
                + '</object> ';
        }
        $(this).before("<div id=\"div" + $(this).attr("id") + "\" style=\" margin-bottom:5px;\" >" + _img + "</div><a class=\"btA\" href=\"javascript:video('" + $.trim($(this).attr("video")) + "','" + $(this).attr("id") + "','');\">视频上传通道</a> ");
        $("input[VideoCutter]").each(function() {
            $("#" + $(this).attr("VideoCutter").split(',')[2]).hide();
            var _img = "";
            if ($.trim($("#" + $(this).attr("VideoCutter").split(',')[2]).val()) != "") {
                _img = "<img style=\"border:1px solid #7F9DB9;\" src=\"" + $.trim($("#" + $(this).attr("VideoCutter").split(',')[2]).val()) + "\" />";
            }
            $("#" + $(this).attr("VideoCutter").split(',')[2]).before("<div id=\"divMinImg" + $(this).attr("id") + "\" style=\" margin-bottom:5px;\" >" + _img + "</div><input id=\"videoCutter" + $(this).attr("id") + "\" type=\"text\" value=\"1\" style=\"width:50px;\" /> 秒 <a class=\"btA2\" href=\"javascript:videoCutter('" + $(this).attr("VideoCutter").split(',')[0] + "','" + $(this).attr("VideoCutter").split(',')[1] + "','" + $(this).attr("VideoCutter").split(',')[2] + "','" + $(this).attr("id") + "');\">截图</a> ");
        });
    });
});
function videoCutter(imgWidth, imgHeight,cSelect, videoSelect) {
    if ($.trim($("#" + videoSelect).val()) == "") {
        alert("先上传视频");
        return;
    }
    var zz = /\D/g;
    if (zz.test($.trim($("#videoCutter" + videoSelect).val()))) {
        alert("截图时间为正整数");
        return;
    }
    $.get("/Tools/VideoCutter.aspx?Src=" + $.trim($("#" + videoSelect).val()).substring($.trim($("#" + videoSelect).val()).lastIndexOf("/") + 1) + "&Time=" + $.trim($("#videoCutter" + videoSelect).val()) + "&Width=" + imgWidth + "&Height=" + imgHeight, function(data) {
        if (data != "error") {
            $("#divMinImg" + videoSelect).html("<img style=\"border:1px solid #7F9DB9;\" src=\"" + data + "\" />");
            $("#" + cSelect).val(data);
        }else {
            $("#" + cSelect).val("");
        }
    });
}
function video(videoWidth, txtSelect) {
    showBox("400", '<div style="line-height:30px; padding:5px 0px 10px 0px;"><p>1、选择要上传的文件：</p><span id="upload1"  style="color:#900;">上传通道加载中...</span><p>建议上传FLV视频文件，仅支持视频文件</p><div id="videoInfo"></div></div>');
    $("#upload1").uploadify({
        'uploader': toolsPath() + 'flash/uploadify2.swf',
        'cancelImg': toolsPath() + 'images/cancel.png',
        'buttonImg': toolsPath() + 'images/selectFile.png',
        'width': 74,
        'height': 12,
        'script': '/Tools/UploadVideo.aspx',
        'fileExt': '*.flv;*.wmv;*.asf;*.rm;*.rmvb;*.mov;*.avi;*.dat;*.mpg;*.mpeg',
        'fileDesc': '*.flv;*.wmv;*.asf;*.rm;*.rmvb;*.mov;*.avi;*.dat;*.mpg;*.mpeg',
        'sizeLimit': 1073741824, //1G
        'simUploadLimit': 10,
        'multi': false,
        'auto': true,
        'onSelect': function(a, b, c) { },
        'onComplete': function(a, b, c, d, e) {
            $(".uploadifyQueueItem").remove();
            if (c.name.substring(c.name.lastIndexOf(".")) == ".flv") {
                toSpSrc(c.filePath, txtSelect);
            }
            else {
                var vname = c.filePath.substring(c.filePath.lastIndexOf("/") + 1);
                var _cutcontent1 = '<p style="color:#900;">您上传的不是FLV文件，正在转换成FLV格式</p>'
                                + '<div style=" border: 2px solid #E5E5E5;background-color: #F5F5F5;margin-top: 5px;padding: 7px 10px;width: 350px; height:30px;">'
                                + '<div style="line-height:16px;">正在转换... ( <label id="barInfo">0%</label> )</div>'
                                + '<div style="background-color: #FFFFFF;border-top: 1px solid #808080;border-left: 1px solid #808080;border-right: 1px solid #C5C5C5;border-bottom: 1px solid #C5C5C5;margin-top: 5px;width: 100%;">'
                                + '<div id="bar" style="background-color: #0099FF;width: 0%;height: 3px;"></div>'
                                + '</div>'
                                + '</div>'
                                + '<div style="display:none;"><iframe src="/Tools/VideoConvert.aspx?Src=' + vname + '&Width=' + videoWidth + '&TxtSelect=' + txtSelect + '"></iframe></div>';
                $("#videoInfo").html(_cutcontent1);
            }
        }
    });
}
function convert(info) {
    $("#barInfo").html(info);
    $("#bar").width(info);
}
function toSpSrc(src, txtSelect) {
    closeBox();
    $("#" + txtSelect).val(src);
    $("#div" + txtSelect).html('<object type="application/x-shockwave-flash" data="' + toolsPath() + 'flash/vcastr3.swf"  style="width:240px;height:160px;">'
                            + '<param name="movie" value="' + toolsPath() + 'flash/vcastr3.swf" />'
                            + '<param name="allowFullScreen" value="true" />'
                            + '<param name="wmode" value="transparent" />'
                            + '<param name="FlashVars" value="xml=<vcastr>'
                            + '<channel>'
                            + '<item>'
                            + '<source>' + src + '</source>'
                            + '<duration></duration>'
                            + '<title></title>'
                            + '</item>'
                            + '</channel>'
                            + '<config>'
                            + '<bufferTime>4</bufferTime>'
                            + '<contralPanelAlpha>0.75</contralPanelAlpha>'
                            + '<controlPanelBgColor>0xff6600</controlPanelBgColor>'
                            + '<controlPanelBtnColor>0xffffff</controlPanelBtnColor>'
                            + '<contralPanelBtnGlowColro>0xffff00</contralPanelBtnGlowColro>'
                            + '<controlPanelMode>normal</controlPanelMode>'
                            + '<defautVolume>0.7</defautVolume>'
                            + '<isAutoPlay>false</isAutoPlay>'
                            + '<isLoadBegin>true</isLoadBegin>'
                            + '<isShowAbout>false</isShowAbout>'
                            + '<scaleMode>showAll</scaleMode>'
                            + '<isRepeat>false</isRepeat>'
                            + '</config>'
                            + '</vcastr>" />'
                            + '</object> ');
    if ($("input[id='" + txtSelect + "'][VideoCutter]").size() > 0) {
        $.get("/Tools/VideoCutter.aspx?Src=" + $.trim($("#" + txtSelect).val()).substring($.trim($("#" + txtSelect).val()).lastIndexOf("/") + 1) + "&Time=1&Width=" + $("#" + txtSelect).attr("VideoCutter").split(',')[0] + "&Height=" + $("#" + txtSelect).attr("VideoCutter").split(',')[1], function(data) {
            if (data != "error") {
                $("#divMinImg" + txtSelect).html("<img style=\"border:1px solid #7F9DB9;\" src=\"" + data + "\" />");
                $("#videoCutter" + txtSelect).val("1");
                $("#" + $("#" + txtSelect).attr("VideoCutter").split(',')[2]).val(data);
            } else {
                $("#" + $("#" + txtSelect).attr("VideoCutter").split(',')[2]).val("");
            }
        });
    }
}